/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bibliinfo;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import utilitarios.Validar;

/**
 *
 * @author Ar0n
 */
public class FrameLogin extends javax.swing.JFrame {

    /**
     * Creates new form Login
     */
    public FrameLogin() {
        initComponents();
        setIcon();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTLogin = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jPSenha = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(445, 315));
        setPreferredSize(new java.awt.Dimension(0, 0));
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(153, 0, 51));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Senha:");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(30, 180, 120, 30);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("InfoBiblio");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(120, 30, 200, 30);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton1.setText("Entrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(230, 235, 150, 40);

        jTLogin.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTLogin.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTLoginKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTLoginKeyReleased(evt);
            }
        });
        getContentPane().add(jTLogin);
        jTLogin.setBounds(230, 110, 150, 30);

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton2.setText("Sair");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(30, 250, 120, 25);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(153, 0, 51));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Login:");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(30, 110, 120, 30);

        jPSenha.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jPSenha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jPSenhaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPSenhaKeyReleased(evt);
            }
        });
        getContentPane().add(jPSenha);
        jPSenha.setBounds(230, 180, 150, 30);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_livro/Books.jpg"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(0, 0, 440, 290);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTLoginKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTLoginKeyPressed
        Validar.validaTexto(jTLogin, 15);
    }//GEN-LAST:event_jTLoginKeyPressed

    private void jTLoginKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTLoginKeyReleased
        Validar.validaTexto(jTLogin, 15);
    }//GEN-LAST:event_jTLoginKeyReleased

    private void jPSenhaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPSenhaKeyPressed
        Validar.validaTexto(jPSenha, 15);
    }//GEN-LAST:event_jPSenhaKeyPressed

    private void jPSenhaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPSenhaKeyReleased
        Validar.validaTexto(jPSenha, 15);
    }//GEN-LAST:event_jPSenhaKeyReleased

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       this.dispose();        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String login = jTLogin.getText();
        char[] s = jPSenha.getPassword();
        String senha = "";
        for(int i =0; i < s.length; i++){
            senha = senha + s[i];
        }
        
        if((login.equalsIgnoreCase("admin")) && (senha.equalsIgnoreCase("admin"))){
            this.dispose();
            FrameMain frameMain = new FrameMain();
            frameMain.setVisible(true);
            frameMain.setLocationRelativeTo(null);
        }else{
            JOptionPane.showMessageDialog(this, "O usuário ou senha esta(ão) incorreto(s)", "", 2);
        }        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FrameLogin login = new FrameLogin();
                login.setVisible(true);
                login.setLocationRelativeTo(null);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPasswordField jPSenha;
    private javax.swing.JTextField jTLogin;
    // End of variables declaration//GEN-END:variables

    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("livro.png")));
    }
}
